package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import java.util.*;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaCompra extends javax.swing.JFrame {
	private JPanel panCompra;
	private JLabel lblCodigo;
	private JLabel lblFecha;
	private JTextField txtCodigo;
	private JTextField txtFecha;
	private JComboBox cmbIngrediente;
	private JTable tblDetalleCompra;
	private JScrollPane scpDetalleCompra;
	private JLabel lblDetalleCompra;
	private JButton btnAceptar;
	private JLabel lblTotal;
	private JButton btnRemover;
	private JButton btnBuscar;
	private JButton btnGuardar;
	private JButton btnSalir;
	private JButton btnCancelar;
	private JTextField txtTotal;
	private JTextField txtCantidad;
	private JLabel lblCantidad;
	private JLabel lblIngrediente;
	
	private VentanaDetalleCompraModeloTabla detalleCompra;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				VentanaCompra inst = new VentanaCompra();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public VentanaCompra() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setTitle("Registrar Compra");
			{
				panCompra = new JPanel();
				getContentPane().add(panCompra, BorderLayout.CENTER);
				panCompra.setLayout(null);
				panCompra.setPreferredSize(new java.awt.Dimension(723, 443));
				panCompra.setBackground(new java.awt.Color(255,255,255));
				{
					lblCodigo = new JLabel();
					panCompra.add(lblCodigo);
					lblCodigo.setText("Codigo Compra");
					lblCodigo.setBounds(39, 29, 109, 18);
					lblCodigo.setForeground(new java.awt.Color(18,6,249));
					lblCodigo.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					lblFecha = new JLabel();
					panCompra.add(lblFecha);
					lblFecha.setText("Fecha");
					lblFecha.setBounds(39, 62, 109, 18);
					lblFecha.setForeground(new java.awt.Color(18,6,249));
					lblFecha.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					txtCodigo = new JTextField();
					panCompra.add(txtCodigo);
					txtCodigo.setBounds(157, 28, 127, 21);
				}
				{
					txtFecha = new JTextField();
					panCompra.add(txtFecha);
					txtFecha.setBounds(157, 61, 127, 21);
				}
				{
					lblIngrediente = new JLabel();
					panCompra.add(lblIngrediente);
					lblIngrediente.setText("Ingrediente");
					lblIngrediente.setBounds(39, 117, 100, 18);
					lblIngrediente.setForeground(new java.awt.Color(18,6,249));
					lblIngrediente.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					ComboBoxModel cmbIngredienteModel = 
						new DefaultComboBoxModel();
					cmbIngrediente = new JComboBox();
					panCompra.add(cmbIngrediente);
					cmbIngrediente.setModel(cmbIngredienteModel);
					cmbIngrediente.setBounds(157, 116, 127, 21);
				}
				{
					lblCantidad = new JLabel();
					panCompra.add(lblCantidad);
					lblCantidad.setText("Cantidad");
					lblCantidad.setBounds(302, 117, 58, 18);
					lblCantidad.setForeground(new java.awt.Color(18,6,249));
					lblCantidad.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					txtCantidad = new JTextField();
					panCompra.add(txtCantidad);
					txtCantidad.setBounds(357, 117, 72, 21);
				}
				{
					btnAceptar = new JButton();
					panCompra.add(btnAceptar);
					btnAceptar.setText("Aceptar");
					btnAceptar.setBounds(471, 116, 88, 21);
					btnAceptar.setForeground(new java.awt.Color(252,221,3));
					btnAceptar.setBackground(new java.awt.Color(18,6,249));
				}
				{
					lblDetalleCompra = new JLabel();
					panCompra.add(lblDetalleCompra);
					lblDetalleCompra.setText("Detalle Compra");
					lblDetalleCompra.setBounds(312, 166, 146, 19);
					lblDetalleCompra.setForeground(new java.awt.Color(18,6,249));
					lblDetalleCompra.setFont(new java.awt.Font("Comic Sans MS",1,14));
				}
				{
					scpDetalleCompra = new JScrollPane();
					panCompra.add(scpDetalleCompra);
					scpDetalleCompra.setBounds(39, 215, 619, 120);
					{
						tblDetalleCompra = new JTable();
						detalleCompra = new VentanaDetalleCompraModeloTabla();
						scpDetalleCompra.setViewportView(tblDetalleCompra);
						tblDetalleCompra.setModel(detalleCompra);
					}
				}
				{
					lblTotal = new JLabel();
					panCompra.add(lblTotal);
					lblTotal.setText("Total Compra");
					lblTotal.setBounds(39, 388, 100, 18);
					lblTotal.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblTotal.setForeground(new java.awt.Color(18,6,249));
				}
				{
					txtTotal = new JTextField();
					panCompra.add(txtTotal);
					txtTotal.setBounds(151, 387, 90, 21);
					txtTotal.setEditable(false);
					txtTotal.setForeground(new java.awt.Color(255,0,0));
				}
				{
					btnCancelar = new JButton();
					panCompra.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(458, 375, 91, 32);
					btnCancelar.setForeground(new java.awt.Color(252,221,3));
					btnCancelar.setBackground(new java.awt.Color(18,6,249));
				}
				{
					btnSalir = new JButton();
					panCompra.add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(567, 375, 91, 32);
					btnSalir.setForeground(new java.awt.Color(252,221,3));
					btnSalir.setBackground(new java.awt.Color(18,6,249));
				}
				{
					btnGuardar = new JButton();
					panCompra.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(351, 375, 91, 32);
					btnGuardar.setForeground(new java.awt.Color(252,221,3));
					btnGuardar.setBackground(new java.awt.Color(18,6,249));
				}
				{
					btnBuscar = new JButton();
					panCompra.add(btnBuscar);
					btnBuscar.setText("Buscar");
					btnBuscar.setBounds(302, 28, 76, 21);
					btnBuscar.setForeground(new java.awt.Color(252,221,3));
					btnBuscar.setBackground(new java.awt.Color(18,6,249));
				}
				{
					btnRemover = new JButton();
					panCompra.add(btnRemover);
					btnRemover.setText("Remover");
					btnRemover.setBounds(570, 116, 88, 21);
					btnRemover.setForeground(new java.awt.Color(252,221,3));
					btnRemover.setBackground(new java.awt.Color(18,6,249));
				}
			}
			pack();
			this.setSize(708, 469);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void addListener(ActionListener actionlistener){
		this.btnAceptar.addActionListener(actionlistener);
		this.btnBuscar.addActionListener(actionlistener);
		this.btnGuardar.addActionListener(actionlistener);
		this.btnCancelar.addActionListener(actionlistener);
		this.btnSalir.addActionListener(actionlistener);
		this.btnRemover.addActionListener(actionlistener);
	}

	public String getCodigo(){
		return this.txtCodigo.getText();
	}
	
	public String getFecha(){
		return this.txtFecha.getText();
	}
	
	public String getCantidad(){
		return this.txtCantidad.getText();
	}
	
	public String getTotal(){
		return this.txtTotal.getText();
	}
	
	public void setTotal(String total){
		txtTotal.setText(total);
	}
	
	public VentanaDetalleCompraModeloTabla getDetalleCompra(){
		return detalleCompra;
	}
	
	public void setDetalleCompra(AbstractTableModel abstractTableModel){
		tblDetalleCompra.setModel(abstractTableModel);
	}
	
	public int seleccionDetalleCompra(){
		return tblDetalleCompra.getSelectedRow();
	}
	
	public void borrarDatos(){
		txtCodigo.setText("");
		txtFecha.setText("");
		txtCantidad.setText("");
		txtTotal.setText("");
		detalleCompra = new VentanaDetalleCompraModeloTabla();
		tblDetalleCompra.setModel(detalleCompra);
	}
	
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	public void cargarComboIngrediente(Vector<String> vector){
		ComboBoxModel cmbIngredienteModel = 
			new DefaultComboBoxModel(vector);
		cmbIngrediente.setModel(cmbIngredienteModel);
	}
	
	public String getNombreIngrediente(){
		return this.cmbIngrediente.getSelectedItem().toString();
	}
	
	public void setCodigo(){
		txtCodigo.setText("");
		txtCodigo.requestFocus();
	}
}
